﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PefStudio.Base;
using PefStudio.StartUp;

namespace PefStudio.Windows
{
    [Export(MainWindow.MainToolStripsContract, typeof(IToolStrip))]
    sealed class ToolStrip1_Test : AbstractToolStrip
    {
        public ToolStrip1_Test()
        {
            this.ID = "Test1";
            this.Text = "Test1";
        }

        [ImportMany("ToolTest", typeof(IToolStripItem), AllowRecomposition = true)]
        private IEnumerable<IToolStripItem> _toolStripItems { get; set; }

        public override void OnImportsSatisfied()
        {
            CreateService.CreateToolStrip(Items, _toolStripItems);
        }
    }

    [Export("ToolTest", typeof(IToolStripItem))]
    sealed class ToolItem1_Test : AbstractToolStripComboBox
    {
        public ToolItem1_Test()
        {
            this.ID = "Test1";
            this.Text = "Test1";

            Visible = false;
        }

        public override void ConditionEvaluate()
        {
            Visible = MainWindow.ActiveDocument is Form1;

            base.ConditionEvaluate();
        }
    }

    [Export(MainWindow.MainToolStripsContract, typeof(IToolStrip))]
    sealed class ToolStrip2_Test : AbstractToolStrip
    {
        public ToolStrip2_Test()
        {
            this.ID = "Test1";
            this.Text = "Test2";

            Visible = false;
        }

        [ImportMany("ToolTest2", typeof(IToolStripItem), AllowRecomposition = true)]
        private IEnumerable<IToolStripItem> _toolStripItems { get; set; }

        public override void OnImportsSatisfied()
        {
            CreateService.CreateToolStrip(Items, _toolStripItems);
        }

        public override void ConditionEvaluate()
        {
            Visible = MainWindow.ActiveDocument is Form1;
        }
    }

    [Export("ToolTest2", typeof(IToolStripItem))]
    sealed class ToolItem2_Test : AbstractToolStripButton
    {
        public ToolItem2_Test()
        {
            this.ID = "Test2";
            this.Text = "Test2";
        }
    }

    [Export(MainWindow.MainMenuContract, typeof(IMenuItem))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    sealed class FM_Test : AbstractMenuItem
    {
        public FM_Test()
        {
            this.ID = "Test";
            this.Text = "Test";

            InsertRelativeToID = "File";
        }

        protected override void OnClick(EventArgs e)
        {
            var frm = Bootstrapper.Container.GetExportedValue<AbstractDocument>("Form");// < AbstractDocument > ("Form");
            MainWindow.ShowDocument(frm);
        }
    }

    [Export(MainWindow.MainMenuContract, typeof(IMenuItem))]
    sealed class Form1Menu_Test : AbstractMenuItem
    {
        public Form1Menu_Test()
        {
            this.ID = "Form1Menu";
            this.Text = "Form1Menu";

            InsertRelativeToID = "File";
            Visible = false;
        }

        protected override void OnClick(EventArgs e)
        {
        }

        public override void ConditionEvaluate()
        {
            Visible = MainWindow.ActiveDocument is Form1;
        }
    }

    [Export(MainWindow.LoadedCommandsContract, typeof(ICommand))]
    class FirstCommand : AbstractCommand
    {
        public override void Run(params object[] args)
        {
            MainWindow.SetMessage("Ready");
            MainWindow.SetProgress(90);
        }
    }

    [Export(MainWindow.ClosingCommandsContract, typeof(ICancelabelCommand))]
    class LastCommand : AbstractCommand, ICancelabelCommand
    {
        public override void Run(params object[] args)
        {
            Cancel = MessageBox.Show("Exit ?", "Info", MessageBoxButtons.YesNo) == DialogResult.No;
        }

        public bool Cancel { get; private set; }
    }
}
